package com.ma4567.remotecontroller.SmallTools.Note;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.ma4567.remotecontroller.MysqlHelper.Notes;
import com.ma4567.remotecontroller.MysqlHelper.TableRequestLog;
import com.ma4567.remotecontroller.RemoteControllerApplication;
import com.ma4567.remotecontroller.ffmpegManager.ffmpegController;
import com.ma4567.remotecontroller.util.Note;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.*;

import java.sql.SQLException;
import java.time.LocalDateTime;
import java.util.ArrayList;

@CrossOrigin
@RestController
public class DeleteNote {
    @RequestMapping(value = "/api/deleteNote", method = RequestMethod.GET)
    public String UpdateNote(HttpServletRequest request,
                             @RequestParam("cookie") String Cookie,
                             @RequestParam("id") int id) throws SQLException {
        ffmpegController.StopStream();
        TableRequestLog.AddLog("Delete Note " + id, Cookie, request.getRemoteAddr());
        if(!RemoteControllerApplication.userManager.JudgeCookie(Cookie)){//鉴cookie
            return JSONObject.toJSONString(new NoteResponse(1, null), SerializerFeature.PrettyFormat);
        }
        else{
            Notes.deleteNote(id);
            return JSONObject.toJSONString(new NoteResponse(0, null), SerializerFeature.PrettyFormat);
        }
    }
}
